# -*- encoding:utf-8 -*-
'''
	pipelinestxt.py.py
	======================
	@descript: 
	@copyright:chinasoft
	@author:guoxiaofei
	@date: 2021-01-26 16:46
	@version:v1.0
'''
# 导入os模块
import os
class Pipelinetxt(object):
    def __init__(self):
        # 创建文件夹名称
        self.filename='output'
        # 判断文件夹是否存在
        if not os.path.exists(self.filename):
            # 不存在则创建
            os.mikdir(self.filename)
    # 该方法用于处理数据
    def process_item(self, item, spider):
        # 当前工程目录下创建文件并关联
        try:
            with open(self.filename+'/'+'data.txt','a',encoding='utf-8') as file:
                # 写入数据,循环遍历
                for i in range(len(item['videoname'])):
                    file.write('电视剧名称:' + item['videoname'][i] + '\n')
                    file.write('电视剧链接:' + item['videourl'][i] + '\n')
                    file.write('电视剧图片链接:' + item['videoimage'][i] + '\n')
        except IOError as err:
            # str()将报错对象转为字符串
            raise('file Error:'+ str(err))
        finally:
            file.close()
        # 返回item
        return item
